
import 'package:flutter/material.dart';
import 'package:flutter_psj/blocs/counter_bloc.dart';

class CountPage extends StatefulWidget {
  const CountPage({Key? key}) : super(key: key);

  @override
  _CountPageState createState() => _CountPageState();
}

class _CountPageState extends State<CountPage> {

  final _bloc = CounterBloC();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text("CountBloc"),),
      body: StreamBuilder(
        stream: _bloc.streamCounter,
        initialData: 0,
        builder: (BuildContext context, AsyncSnapshot<int> snapshot){
          return Center(
            child: Text(
              snapshot.data.toString(),
              style: const TextStyle(fontSize: 40, fontWeight: FontWeight.w300),
            ),
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        child: const Icon(Icons.add),
        onPressed: (){
          _bloc.addCount();
        },
      ),
    );
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    _bloc.dispose();
  }
}
